#include "pitches.h"
volatile float M;
volatile float dis_L;
volatile float dis_R;
volatile float dis_M;
float checkdistance_40_4() {
  digitalWrite(40, LOW);
  delayMicroseconds(2);
  digitalWrite(40, HIGH);
  delayMicroseconds(10);
  digitalWrite(40, LOW);
  float distance = pulseIn(4, HIGH) / 58.00;
  delay(10);
  return distance;
}
float checkdistance_41_5() {
  digitalWrite(41, LOW);
  delayMicroseconds(2);
  digitalWrite(41, HIGH);
  delayMicroseconds(10);
  digitalWrite(41, LOW);
  float distance = pulseIn(5, HIGH) / 58.00;
  delay(10);
  return distance;
}
float checkdistance_42_6() {
  digitalWrite(42, LOW);
  delayMicroseconds(2);
  digitalWrite(42, HIGH);
  delayMicroseconds(10);
  digitalWrite(42, LOW);
  float distance = pulseIn(6, HIGH) / 58.00;
  delay(10);
  return distance;
}
void setup(){
  M = 0;
  pinMode(36, INPUT);
  Serial.begin(9600);
  dis_L = 0;
  dis_R = 0;
  dis_M = 0;
  pinMode(40, OUTPUT);
  pinMode(4, INPUT);
  pinMode(41, OUTPUT);
  pinMode(5, INPUT);
  pinMode(42, OUTPUT);
  pinMode(6, INPUT);
  pinMode(38, OUTPUT);
  pinMode(39, OUTPUT);
}
void loop(){
  dis_L = checkdistance_40_4();
  dis_R = checkdistance_41_5();
  dis_M = checkdistance_42_6();
  M = analogRead(37);
  Serial.println(dis_L);
  Serial.println(dis_R);
  Serial.println(dis_M);
  Serial.println(M);
  if dis_L < 20
    tone(38, NOTE_C4, 125);
  if dis_R < 20
    tone(39, NOTE_C4, 125);
  if dis_M > 20{
    tone(38, NOTE_C4, 125);
    tone(39, NOTE_C4, 125);
  }
  if M == 1{
    tone(38, NOTE_C5, 125);
    tone(39, NOTE_C5, 125);
  }    
}
